//
//  APDiscoveryCollectionViewCell.m
//  AqualPolo
//
//  Created by dong on 2024/5/3.
//

#import "APDiscoveryCollectionViewCell.h"

@implementation APDiscoveryCollectionViewCell


- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.contentView.backgroundColor = UIColor.clearColor;
        self.backgroundColor = UIColor.clearColor;
        _coverImageView = [[UIImageView alloc] init];
        _coverImageView.contentMode = UIViewContentModeScaleAspectFill;
        _coverImageView.layer.cornerRadius = 8;
        _coverImageView.layer.masksToBounds = true;
        [self.contentView addSubview:_coverImageView];
        [_coverImageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.left.right.equalTo(self.contentView);
            make.height.mas_equalTo(204);
        }];
        
        UIView *coverView = [[UIView alloc] init];
        [_coverImageView addSubview:coverView];
        [coverView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edges.equalTo(_coverImageView);
        }];
        [coverView setGradientBackgroundWithColors:@[LYRGBAColor(0, 0, 0,0.5),LYRGBAColor(0, 0, 0, 0)] locations:@[@0,@1] startPoint:CGPointMake(0.5, 0) endPoint:CGPointMake(0.5, 1)];
        
        
  
        
        UIView *bottomView = [[UIView alloc] init];
        bottomView.backgroundColor = LYRGBAColor(255, 255, 255, 0.3);
        bottomView.layer.cornerRadius = 8;
        bottomView.layer.borderWidth = 1;
        bottomView.layer.borderColor = LYRGBColor(45, 116, 255).CGColor;
        [self.contentView addSubview:bottomView];
        [bottomView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.bottom.equalTo(self.contentView);
            make.size.mas_equalTo(CGSizeMake(100, 32));
            make.centerX.equalTo(self.contentView);
        }];
        
        _contentLabel = [[UILabel alloc] init];
        _contentLabel.textColor = [UIColor whiteColor];
        _contentLabel.font = [LYFont fontWithSize:12 fontName:LYFontNamepfr];
        _contentLabel.textAlignment = NSTextAlignmentLeft;
        [self.contentView addSubview:_contentLabel];
        [_contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.contentView).offset(8);
            make.bottom.equalTo(bottomView.mas_top).offset(-4);
            make.right.equalTo(self.contentView).offset(-8);
        }];
        
        _avatarControl = [[APAvatarControl alloc] init];
        [self.contentView addSubview:_avatarControl];
        [_avatarControl mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.left.equalTo(self.contentView).offset(4);   
        }];
        
        
        
        
        _followButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [self.contentView addSubview:_followButton];
        [_followButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.contentView).offset(22);
            make.left.equalTo(self.contentView).offset(24);
            make.size.mas_equalTo(CGSizeMake(12, 12));
        }];
        
        _moreButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [_moreButton setBackgroundImage:[UIImage imageNamed:@"discovery_more"] forState:UIControlStateNormal];
        [self.contentView addSubview:_moreButton];
        [_moreButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self.contentView).offset(-4);
            make.centerY.equalTo(_avatarControl);
            make.size.mas_equalTo(CGSizeMake(24, 24));
        }];
        
        
        _nameLabel = [[UILabel alloc] init];
        _nameLabel.textColor = [UIColor whiteColor];
        _nameLabel.font = [LYFont fontWithSize:12 fontName:LYFontNamepfr];
        _nameLabel.textAlignment = NSTextAlignmentLeft;
        [self.contentView addSubview:_nameLabel];
        [_nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(_avatarControl.mas_right).offset(8);
            make.top.bottom.equalTo(_avatarControl);
            make.right.equalTo(_moreButton.mas_left);
        }];
        

        _upvoteButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [_upvoteButton setImage:[UIImage imageNamed:@"upvote_n"] forState:UIControlStateNormal];
        [_upvoteButton setImage:[UIImage imageNamed:@"upvote_h"] forState:UIControlStateSelected];        
        [bottomView addSubview:_upvoteButton];
        [_upvoteButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(bottomView.mas_right).offset(-12);
            make.centerY.equalTo(bottomView);
            make.size.mas_equalTo(CGSizeMake(24, 24));
        }];
        
        _ballButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [bottomView addSubview:_ballButton];
        [_ballButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(bottomView).offset(12);
            make.centerY.equalTo(bottomView);
            make.size.mas_equalTo(CGSizeMake(24, 24));
        }];
        
        
    }
    return self;
}

@end
